<template>
  <div class="goods-tabs">
    <nav>
      <a
        href="javascript:;"
        :class="{ active: activeCom === 'goodsDetails' }"
        @click="activeCom = 'goodsDetails'"
        >商品详情</a
      >
      <a
        href="javascript:;"
        :class="{ active: activeCom === 'goodsComment' }"
        @click="activeCom = 'goodsComment'"
        >商品评价 <span>({{ store.state.user.counts }})</span>
      </a>
    </nav>
    <!-- 切换内容的地方,这个位置显示对应的组件GoodsDetails或者GoodsComment -->
    <component :is="activeCom"></component>
  </div>
</template>

<script>
import { ref, inject } from 'vue'
import goodsComment from './goods-comment.vue'
import goodsDetails from './goods-details.vue'
import { useStore } from 'vuex'
export default {
  name: 'GoodsTabs',
  components: { goodsDetails, goodsComment },
  setup() {
    const store = useStore()
    //  默认展示商品详情组件，GoodsDetails商品详情，GoodsComment商品评价
    const activeCom = ref('goodsDetails')
    // 使用goods数据
    const goods = inject('goods')
    return { activeCom, goods, store }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background-color: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: '';
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background-color: @color;
        }
      }
    }
  }
}
</style>
